package com.hitrust.gs.dao;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

import com.hitrust.gs.bean.GSManufactureBean;
import com.hitrust.gs.bean.GSManufactureFilterUploadBean;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.util.exception.GSException;

import com.hitrust.gs.lib.db.GSBaseDAO;

/**
 * @author Jackey
 *
 * 处理筛选产品信息的逻辑
 */
public class GSManufactureFilterUploadDAO extends GSBaseDAO
{

    /**
     * 查询筛选产品信息
     * @param manufactureId         产品编码
     * @return                      筛选产品数据对象
     * @throws GSException
     */
    public GSManufactureFilterUploadBean getManufacture(String manufactureId) throws GSException 
    { 
		String tSql = "select * from GS_Manufacture_filter_inport where GS_MANUFACTURE_ID = ?";
		ArrayList tList = null;
		GSManufactureFilterUploadBean tGSManufactureFilterUploadBean = null;
		Object[] tObj = {manufactureId};
		try{
			tList = this.executeQuery(new GSManufactureBean(),tSql,tObj);
			if(tList.size() >0 ){
				tGSManufactureFilterUploadBean = (GSManufactureFilterUploadBean)tList.get(0);
			}
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		
		return tGSManufactureFilterUploadBean;
    }
     
    /**
     * 在筛选产品信息中新增一笔记录
     * @param aGSManufactureFilterUploadBean
     * 
     * @return boolean
     * 
     * @throws CUPSException
     */
    public boolean add(GSManufactureFilterUploadBean aGSManufactureFilterUploadBean) throws GSException 
    {

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String buf = df.format(new java.util.Date(System.currentTimeMillis()));
        
        String tSql = "INSERT into GS_Manufacture_filter_inport (GS_MANUFACTURE_ID, GS_CONCENTRICITY_ID, GS_INPORT_TIME) VALUES  (?, ?, ?)";

        Object[] tObject = new Object[3] ;
        tObject[0] = aGSManufactureFilterUploadBean.getGs_manufacture_id();
        tObject[1] = aGSManufactureFilterUploadBean.getGs_concentricity_id();
        tObject[2] = buf;
        
        boolean tResult = false;
        try {
            tResult = executeUpdate(tSql, tObject);

        } catch (Exception ex) {
            GSLogWriter.error(this, ex.toString());
            throw new GSException("");
        }

        return tResult;
    }
    
    /**
     * 筛选产品信息是否存在
     * @param aManfactureId
     * @return boolean
     * @throws GSException
     */
    public boolean isExist(String aManfactureId) throws GSException
    {
        String tSql = "select * from GS_Manufacture_filter_inport where GS_MANUFACTURE_ID = ?";
        boolean tFlag = false;
        Object[] tObj = {aManfactureId};
        try{
            ArrayList tList = this.executeQuery(new GSManufactureFilterUploadBean(),tSql,tObj);
            if( tList.size() > 0 ){
                tFlag = true;
            }
        }catch(Exception e){
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E19999,GSException.E19999_MSG);
        }
        return tFlag;
    }
    
    /**
     * 筛选产品信息是否存在
     * @param aManfactureId
     * @return boolean
     * @throws GSException
     */
    public boolean isExist(GSManufactureBean tGSManufactureBean) throws GSException
    {
        String tSql = "select * from GS_Manufacture_filter_inport where GS_MANUFACTURE_ID = ? or GS_CONCENTRICITY_ID = ?";
        boolean tFlag = false;
        Object[] tObj = {tGSManufactureBean.getGs_manufacture_id(),tGSManufactureBean.getGs_concentricity()};
        try{
            ArrayList tList = this.executeQuery(new GSManufactureFilterUploadBean(),tSql,tObj);
            if( tList.size() > 0 ){
                tFlag = true;
            }
        }catch(Exception e){
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E19999,GSException.E19999_MSG);
        }
        return tFlag;
    }
    
    /**
     * 在筛选产品信息表中删除一笔记录
     * @param aManfactureId 产品编号
     *            
     */
    public boolean delete(String aManfactureId) throws GSException 
    {
        String tSql = "delete from GS_Manufacture_filter_inport where GS_MANUFACTURE_ID=?";
        Object[] tObject = { aManfactureId };
        boolean tResult = false;
        try {
            tResult=executeUpdate(tSql, tObject);
        } catch (Exception ex) {
            GSLogWriter.error(this, ex.getMessage());
            throw new GSException(ex.getMessage());
        }

        return tResult;
    }
    
    /**
     * 在筛选产品信息表中更新一笔记录
     * @param GSManufactureFilterUploadBean
     * @throws CUPSException
     * return boolean
     */
    public boolean modify(GSManufactureFilterUploadBean aGSManufactureFilterUploadBean) throws GSException 
    {
        String tSql = "UPDATE GS_Manufacture_filter_inport SET GS_INPORT_TIME=? ,GS_CONCENTRICITY_ID=?" +
                " where GS_MANUFACTURE_ID=?";
        Object[] tObject = new Object[3];
        tObject[0] = aGSManufactureFilterUploadBean.getGs_inport_time();  
        tObject[1] = aGSManufactureFilterUploadBean.getGs_concentricity_id();
		tObject[2] = aGSManufactureFilterUploadBean.getGs_manufacture_id();      

        boolean tResult = false;
        try {
            tResult = executeUpdate(tSql, tObject);
        } catch (Exception ex) {
            GSLogWriter.error(this, ex.getMessage());
            throw new GSException(ex.getMessage());
        }
        return tResult;
    }

}
